<template>
	<div class="common-layout">
	    <el-container>
			<el-header><Header></Header></el-header>
			<el-main>
				<h3>订单设置</h3>
				<ul>
					<li>
						<h4>自动取消订单</h4>
						<div class="part1">
							<el-form-item>
								<span style="margin-right: 15px;width: 60px; text-align: center;">提交订单</span>
								<el-input style="width: 220px; margin-right: 15px;" v-model="canceltime"></el-input >
								<span>分中未付款，自动取消订单</span>
							</el-form-item>	
							<div class="cell" style="color: #ccc;">订单取消时间必须在10-1440分钟之间</div>
							<div class="cell">
								<el-checkbox>自动取消订单</el-checkbox>
							</div>
						</div>
					</li>
					<li>
						<h4>自动确认收货</h4>
						<div class="part1">
							<el-form-item>
								<span style="margin-right: 15px;width: 60px;text-align: center;">发货后</span>
								<el-input style="width: 220px; margin-right: 15px;" v-model="overgettime"></el-input >
								<span>天，自动确认收货</span>
							</el-form-item>	
							<div class="cell" style="color: #ccc;">自动确认收货时间必须在1-30天之间</div>
							<div class="cell">
								<el-checkbox>自动确认收货</el-checkbox>
							</div>
						</div>
					</li>
					<li>
						<h4>确认收货后售后</h4>
						<div class="part1">
							<el-form-item>
								<span style="margin-right: 15px;width: 60px;text-align: center;">确认收货</span>
								<el-input style="width: 220px; margin-right: 15px;" v-model="notbacktime"></el-input >
								<span>天内，可申请售后</span>
							</el-form-item>	
							<div class="cell" style="color: #ccc;">确认收货后售后时间必须在1-30天之间</div>
							<div class="cell">
								<el-checkbox>确认收货后不支持售后</el-checkbox>
							</div>
						</div>
					</li>
					
					<li>
						<h4>评价设置</h4>
						<div class="part1">
							<div>
								<span style="margin-right: 15px;font-size: 14px;">评价开关</span>
								 <el-radio-group v-model="evaluate">
								    <el-radio :value="1">开启</el-radio>
								    <el-radio :value="0">关闭</el-radio>
								  </el-radio-group>
							</div>
							<div>
								<span style="margin-right: 15px;font-size: 14px;">评价审核</span>
								 <el-radio-group v-model="evaluateaudit">
								    <el-radio :value="1">开启</el-radio>
								    <el-radio :value="0">关闭</el-radio>
								  </el-radio-group>
							</div>
							<div>
								<span style="margin-right: 15px;font-size: 14px;">评价显示</span>
								 <el-radio-group v-model="evaluateshow">
								    <el-radio :value="1">开启</el-radio>
								    <el-radio :value="0">关闭</el-radio>
								  </el-radio-group>
							</div>
						</div>
					</li>
					
					<li>
						<h4>发票设置</h4>
						<div class="part1">
							<div>
								<span style="margin-right: 15px;font-size: 14px;">发票开关</span>
								 <el-radio-group v-model="invoice">
								    <el-radio :value="1">开启</el-radio>
								    <el-radio :value="0">关闭</el-radio>
								  </el-radio-group>
							</div>
							<div>
							
								<el-form-item>
									<span style="margin-right: 15px;font-size: 14px;">发票内容</span>
									<el-input
									    v-model="content"
									    style="width: 240px"
									    :rows="2"
									    type="textarea"
									    placeholder="Please input"
									  />
									<!-- <el-button>添加</el-button> -->
								</el-form-item>
							</div>
							<div>
								<span style="margin-right: 15px;font-size: 14px;">发票类型</span>
								 <el-radio-group v-model="invoicetype">
								    <el-radio :value="1">电子发票</el-radio>
								    <el-radio :value="0">纸质发票</el-radio>
								  </el-radio-group>
							</div>
						</div>
					</li>
				</ul>
				<el-button
				type="primary"
				style="margin-left:150px;"
				@click="makeset"
				>保存</el-button>
			</el-main>
	    </el-container>
	</div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import Header from "@/components/Header.vue"
import { ordercancel,orderover,notbackpay,allorderset,addorderset} from '@/api';
import { ElMessage, ElMessageBox } from 'element-plus'
let evaluate=ref(0)
let evaluateaudit=ref (0)
let evaluateshow=ref (0)
let invoice=ref (0)
let invoicetype=ref (0)
const content=ref()
//设置自动取消订单时间
const canceltime=ref()
const setcancelorder=async ()=>{
	let res = await ordercancel({
		autoCancel:Number(canceltime.value)
	})
		// console.log(res);
}
//设置自动默认收货时间
const overgettime=ref()
const setgetgoods=async ()=>{
	let res = await orderover({
		autoReceipt:Number(overgettime.value)
	})
		// console.log(res);
}
//设置默认不可退款时间
const notbacktime=ref()
const setnotback=async ()=>{
	let res = await notbackpay({
		backDay:Number(notbacktime.value)
	})
		// console.log(res);
}
//获取站点订单设置
const getorderset=async ()=>{
	let res = await allorderset({
		siteId:Number(sessionStorage.getItem("siteId"))
	})
	canceltime.value=res[0].autoCancel
	overgettime.value=res[0].autoReceipt
	notbacktime.value=res[0].backDay
	content.value=res[0].defaultInvoice
	evaluate.value=Number(res[0].allowComment)
	evaluateaudit.value=Number(res[0].needExamine)
	evaluateshow.value=Number(res[0].showComment)
	invoice.value=Number(res[0].allowInvoice)
	invoicetype.value=Number(res[0].invoiceStatus)
	// console.log(res);
}
//添加设置订单设置
const addupdateset=async ()=>{
	let res = await addorderset({
		"autoCancel":canceltime.value,
		"autoReceipt":overgettime.value,
		"allowComment":evaluate.value,
		"needExamine":evaluateaudit.value,
		"showComment":evaluateshow.value,
		"allowInvoice":invoice.value,
		"defaultInvoice":content.value,
		// goodsId:
		"invoiceStatus":invoicetype.value,
		"siteId":sessionStorage.getItem("siteId"),
		"backDay":notbacktime.value
	})
		// console.log(res);
		ElMessage({
		    message:"保存成功",
		    type: 'success',
		})
}


const makeset=()=>{
	// setcancelorder()
	// setgetgoods()
	// setnotback()
	addupdateset()
	
}

onMounted(()=>{
	//获取该站点订单设置
	getorderset()
})
</script>

<style lang="less" scoped>
	h3{
		// margin-left: 50px;
		margin-bottom: 20px;
		// margin-top: 20px;
		display: flex;
		justify-content: space-between;
		margin-right: 100px;
	}
	h4{
		margin-left: 100px;
		margin-bottom: 20px;
	}
	.part1{
		margin-left: 150px;
		margin-bottom: 20px;
		.cell{
			margin-left:70px;
		}
	}
	.el-form-item{
		margin-bottom: 0px;
	}
	.common-layout{
		background: #f2f3f5;
		.el-header{
			padding:0 !important;
			height: 10vh;
		}
		.el-main{
			height: 86vh;
			// padding:0;
			width: 98%;
			background: #fff;
			margin: 10px auto;
		}
	}
	li{
		list-style: none;
	}
</style>